﻿using System;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace referrals.Layouts.referrals
{
    public partial class Search : LayoutsPageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string strSelect = "SELECT Contacts.ClientID, Contacts.ReasonReferred, Contacts.DateReferred, Contacts.ReferredBy, Contacts.Description, Contacts.Urgency, Contacts.Type, Contacts.DNW, Contacts.ContactBy1, Contacts.ContactBy2, Contacts.AssessmentDate, Contacts.ReportFeedback, Contacts.ReportSent, Contacts.referralResponse, Contacts.DNW, Contacts.RefOutcome, Contacts.Closed, Contacts.RefDiscussion, Contacts.RefDiscussion, Contacts.FOutcome, Contacts.PapersLocation FROM Contacts WHERE (((Contacts.ClientID)='" + Request.QueryString["uid"] + "')) ORDER BY Contacts.DateReferred DESC";
            using (SqlConnection conn = new SqlConnection(Connection.GetConnStrSql()))
            {
                //SqlConnection conn = connection.GetConnection();
                SqlCommand sqlCommand = new SqlCommand(strSelect, conn);
                conn.Open();
                SqlDataReader reader = sqlCommand.ExecuteReader();
                GridView1.RowDataBound += new GridViewRowEventHandler(GridView1_RowDataBound);

                GridView1.DataSource = reader;
                GridView1.DataBind();
                //conn.Close();

            }
          
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            // comments go here
            e.Row.Cells[0].Visible = false;
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                HyperLink myLink = new HyperLink();
                myLink.Text = e.Row.Cells[1].Text;
                e.Row.Cells[1].Controls.Add(myLink);
                myLink.NavigateUrl = "open.aspx?uid=" + e.Row.Cells[0].Text;
            }
        }
    }
}
